﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Percolation
{
    public enum NetTypeEnum
    {
        [DescriptionAttribute("Vertical gradient")]
        VerGradient,
        [DescriptionAttribute("Horizontal gradient")]
        HorGradient,
        [DescriptionAttribute("Random")]
        Random,
        [DescriptionAttribute("Chess")]
        Chess,
        [DescriptionAttribute("Strip row")]
        StripRow,
        [DescriptionAttribute("Strip column")]
        StripColumn,
        [DescriptionAttribute("Ring closed")]
        RingClosed,
        [DescriptionAttribute("Ring hollow")]
        RingHollow,
        [DescriptionAttribute("Rain")]
        Rain,
        [DescriptionAttribute("Dotted row")]
        DottedRow,
        [DescriptionAttribute("Dotted column")]
        DottedColumn,
        [DescriptionAttribute("H-Test")]
        HTest,
        [DescriptionAttribute("Shifted H-Test")]
        ShiftedHTest,
        [DescriptionAttribute("Half-shifted H-Test")]
        HalfShiftedHTest
    }

    public static class EnumUtils
    {
        public static string GetString(this Enum e)
        {
            var s = e.ToString();
            var fi = e.GetType().GetField(s);
            var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
                typeof(DescriptionAttribute), false);
            if (attributes.Length > 0)
                s = attributes[0].Description;
            return s;
        }
    }

    public enum eNetComponent
    {
        eRow, eColumn
    }

    public class NetParams
    {
        public int NetWidth { get; private set; }
        public int NetHeight { get; private set; }
        public NetTypeEnum NetType { get; private set; }

        public NetParams(NetTypeEnum netType, int netWidth, int netHeight)
        {
            NetType = netType;
            NetWidth = netWidth;
            NetHeight = netHeight;
        }
    }

    public class RandomNetParams : NetParams
    {
        public double Probability { get; private set; }

        public RandomNetParams(int netWidth, int netHeight, double probability)
            : base(NetTypeEnum.Random, netWidth, netHeight)
        {
            Probability = probability;
        }
    }

    public class GradientNetParams : NetParams
    {
        public double Probability0 { get; private set; }
        public double Probability1 { get; private set; }

        public GradientNetParams(bool vertical, int netWidth, int netHeight, double probability0, double probability1)
            : base(vertical ? NetTypeEnum.VerGradient : NetTypeEnum.HorGradient, netWidth, netHeight)
        {
            Probability0 = probability0;
            Probability1 = probability1;
        }
    }
}
